<?php

class YoutubeComponent extends Object {

	// function to parse a video <entry>
	function get_data($url, $service_id) {
		$vid = $this->get_id($url);
		// set video data feed URL
		$feedURL = 'http://gdata.youtube.com/feeds/api/videos/' . $vid;
		// read feed into SimpleXML object
		$entry = simplexml_load_file($feedURL);
		$obj= new stdClass;

		// get nodes in media: namespace for media information
		$media = $entry->children('http://search.yahoo.com/mrss/');
		$obj->title = $media->group->title;
		$obj->description = $media->group->content;

		// get video player URL
		$obj->html = '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/'.$vid.'&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/'.$vid.'&hl=en&fs=1&ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>';; 

		// get video thumbnail
		$obj->thumbnail_url = 'http://img.youtube.com/vi/'.$vid.'/1.jpg';

		// return object to caller  
		return $obj;      
	}

	function get_id($url){
		$url_query = parse_url($url, PHP_URL_QUERY);
		parse_str($url_query);
		if(isset($v)){
			return $v;
		} else {
			return false;
		}
		
	}
}
?>